package com.patrol.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.patrol.pojo.User;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserDao extends BaseMapper<User> {

    @Select("select * from user where userId = #{userId}")
    User findUserById(@Param("userId") Integer userId);
    //注册成功，插入一条数据
    //@Insert("insert into admin_user(username,password,authority) values (#{username},#{password},#{authority})")
    // int add(AdminUser user);
    //检验注册的username是否已经存在数据库中，通过User类创建findByUsername对象，传进username进行与数据库比较
    @Select("select * from user where username = #{username}")
    User findByUsername(@Param("username") String username);
    //登录用：检验账号密码是否正确
    @Select("select * from user where username = #{username} and password = #{password}")
    User findByUsername_login(@Param("username") String username,
                                   @Param("password") String password);
    //修改个人信息
    @Update("update user set realName = #{user.realName}, password = #{user.password}, sex= #{user.sex}, email=#{user.email},tel=#{user.tel} WHERE username = #{username}")
    Integer updateUser(User user,@Param("username") String username);
    //添加管理员头像
    @Update("update user set img = #{url} where username = #{username}")
    Integer updatePhotoUrl(@Param("username") String username, @Param("url") String url);

    //添加管理员头像
    @Update("update user set img = #{url} where userId = #{userId}")
    Integer xgUpdatePhotoUrl(@Param("userId") Integer userId, @Param("url") String url);

    //检验注册的img是否已经存在数据库中，通过User类创建findByUrl对象，传进url进行与数据库比较
    @Select("select * from user where img = #{url}")
    User findByUrl(@Param("url") String url);

    @Select("select img from user where username=#{username}")
    String selectUserImgUrl(String username);

    @Update("update user set password = #{pwd} where email = #{email}")
    boolean updatePwd(String pwd,String email);

    @Select("select * from user where realName=#{realName}")
    User findByrealName(String realName);

    @Select("select * from user where authority=1 and is_deleted=0")
    List<User> selectAllXG();

    @Update("update user set is_assigned=1 where userId=#{u}")
    int changeUserState(int u);

    @Update("update user set is_assigned=0 where userId=#{u}")
    int changeUserKXState(int u);

    @Select("select realName from user where userId=#{adminId}")
    String selectUserRealName(Integer adminId);

    @Select("select count(*) from user where authority=1")
    int selectXGUserNum();

    @Select("select is_assigned from user where userId=#{userId}")
    int selectXGUserStatus(Integer userId);
}